#!/usr/bin/env/ python
# -*- coding: utf-8

"""
@project: python-file
@author: admin
@time: 2022/6/29
"""

import allure
from selenium.webdriver.common.by import By
from base.app.base import BasePage, BaseHandle

'''登录类'''
# 定义对象库层
class LoginPage(BasePage):
	
	def __init__(self):
		super().__init__()
		# 菜单栏-我的
		self.me_btn = By.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout[5]/android.widget.LinearLayout/android.widget.ImageView"
		# 手机号
		self.iphone = By.ID, "com.szlanyou.nissaniov:id/etCodePhone"
		# 获取验证码
		self.verification_code = By.ID, "com.szlanyou.nissaniov:id/tvCodeGetCode"
		# 同意授权
		self.me_determine = By.ID, "com.szlanyou.nissaniov:id/ivSelect"
		# 点击登录
		self.login_btn = By.ID, "com.szlanyou.nissaniov:id/tvLoginUseCode"

	# 定位菜单栏-我的
	def find_me_btn(self):
		return self.get_element(self.me_btn)
	
	# 定位手机号输入框
	def find_iphone(self):
		return self.get_element(self.iphone)
	
	# 定位获取验证码按钮
	def find_verification_code(self):
		return self.get_element(self.verification_code)
	
	# 定位阅读同意按钮
	def find_me_determine(self):
		return self.get_element(self.me_determine)
	
	# 定位登录按钮
	def find_login_btn(self):
		return self.get_element(self.login_btn)

# 定义操作层
class LoginHandle(BaseHandle):

	def __init__(self):
		self.login_page = LoginPage()

	@allure.step(title = "点击菜单栏-我的")
	def click_me_btn(self):
		self.click_element(self.login_page.find_me_btn())
	
	@allure.step(title = "输入手机号")
	def sendkeys_iphone(self):
		self.input_text(self.login_page.find_iphone(), "88821090008")
	
	@allure.step(title = "点击获取验证码")
	def click_verification_code(self):
		self.click_element(self.login_page.find_verification_code())
	
	@allure.step(title = "点击阅读同意按钮")
	def click_me_determine(self):
		self.click_element(self.login_page.find_me_determine())
	
	@allure.step(title = "点击登录按钮")
	def click_login_btn(self):
		self.click_element(self.login_page.find_login_btn())

# 定义业务层
class LoginProxy:

	def __init__(self):
		self.login_handle = LoginHandle()

	# 登录业务
	def login(self):
		self.login_handle.click_me_btn()    # 点击菜单栏-我的
		self.login_handle.sendkeys_iphone()   # 输入手机号
		self.login_handle.click_verification_code()   # 点击获取验证码
		self.login_handle.click_me_determine()    # 点击阅读同意
		self.login_handle.click_login_btn()   # 点击登录按钮